import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

public class HistoryData{
	
	private HashMap<Integer, Integer> stations;
	
	private HashMap<Integer, ArrayList<Data>> historyMap;
	
	/**
	 * Creates a HistoryData object. This object is used for extrapolation of missing data
	 * @param stations All the station
	 */
	public HistoryData(HashMap<Integer, Integer> stations){
		this.stations = stations;
		createHistoryMap();	
	}
	
	/**
	 * Creates the history map
	 */
	public void createHistoryMap(){
		this.historyMap = new HashMap<Integer, ArrayList<Data>>();	
		Set<Integer> keys = stations.keySet();		
		for(Integer key : keys) {
			historyMap.put(key, new ArrayList<Data>());
		}	
	}
	
	/**
	 * Adds data to history map
	 * @param data Data object which holds the data
	 */
	public synchronized void addData(Data data){		
		if(historyMap.get(data.getStn()).size() == 30){
			historyMap.get(data.getStn()).remove(0);
		}
		historyMap.get(data.getStn()).add(data);
	}
	
	/**
	 * Returns the history in a ArrayList
	 * @param stn station number
	 * @return historyMap Holds all data objects corresponding the station number
	 */
	public synchronized ArrayList<Data> getHistory(int stn){		
		if(historyMap.size() > 0){			
			return historyMap.get(stn);
		}
		else{
			return null;
		}
	}
}